package com.service.impl;

import com.dao.DeliveryAddressMapper;
import com.model.DeliveryAddress;
import com.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DeliveryAddressServiceImpl implements DeliveryAddressService {
    @Autowired
    private DeliveryAddressMapper mapper;
    @Override
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId) {
        List<DeliveryAddress> list= new ArrayList<>();
        try {
            list = mapper.listDeliveryAddressByUserId(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;

    }

    @Override
    public DeliveryAddress getDeliveryAddressById(int daId) {
        DeliveryAddress deliveryaddress=null;
        try {
           deliveryaddress= mapper.getDeliveryAddressById(daId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return deliveryaddress;
    }

    @Override
    public int saveDeliveryAddress(String contactName, int contactSex, String contactTel, String address, String userId) {
        int issave=-1;
        try {
            issave= mapper.saveDeliveryAddress(contactName,contactSex,contactTel,address,userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return issave;

    }

    @Override
    public int updateDeliveryAddress(int daId, String contactName, int contactSex, String contactTel, String address, String userId) {
        int issave=-1;
        try {
            issave= mapper.updateDeliveryAddress(daId,contactName,contactSex,contactTel,address,userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return issave;
    }

    @Override
    public int removeDeliveryAddress(int daId) throws Exception {
        int issave=-1;
        try {
            issave= mapper.removeDeliveryAddress(daId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return issave;
    }
}
